package com.ity.teamanagement.controller;

import com.ity.teamanagement.annocation.CheckAuthorityStatus;
import com.ity.teamanagement.annocation.CheckLoginState;
import com.ity.teamanagement.entity.inputParam.BackAddTeaMessageParam;
import com.ity.teamanagement.entity.inputParam.BackSearchTeaParam;
import com.ity.teamanagement.entity.inputParam.BackUpdateTeaMessageParam;
import com.ity.teamanagement.entity.inputParam.BackUpdateTeaRemarksMessageParam;
import com.ity.teamanagement.result.Result;
import com.ity.teamanagement.service.TeaManagementService;
import com.ity.teamanagement.service.TeaSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author coderFu
 * @create 2021/5/24
 */
@RestController
@Api(tags = "后台茶种管理模块")
@RequestMapping("/teaManagement")
public class TeaManagementController {

    @Autowired
    private TeaSearchService teaSearchService;

    @Autowired
    private TeaManagementService teaManagementService;

    @GetMapping("/backFindAllTeaListMessage")
    @ApiOperation("后台根据条件查看所有茶种信息列表")
    @CheckLoginState
    public Result backFindAllTeaMessage(@PageableDefault(page = 0,size = 10)Pageable pageable, BackSearchTeaParam backSearchTeaParam){
        return Result.success(teaSearchService.backFindAllTeaListMessageByCondition(pageable,backSearchTeaParam));
    }

    @GetMapping("/backFindTeaDetailsMessageById")
    @ApiOperation("后台根据茶种id查询茶种详情信息（主信息）")
    @CheckLoginState
    public Result findTeaDetailsMessageById(@RequestParam("id") Long id){
        return Result.success(teaSearchService.findTeaDetailsMessageById(id));
    }

    @GetMapping("/backFindRemarksTeaDetailsMessageById")
    @ApiOperation("根据茶种id查询茶种详情信息（附加信息）")
    @CheckLoginState
    public Result findRemarksTeaDetailsMessageById(@RequestParam("id") Long id){
        return Result.success(teaSearchService.findRemarksTeaDetailsMessageById(id));
    }

    @PostMapping("/backAddNewTeaVariety")
    @ApiOperation("后台添加茶树品种信息")
    @CheckAuthorityStatus
    public Result backAddNewTeaVariety(@RequestBody BackAddTeaMessageParam backAddTeaMessageParam){
        teaManagementService.backAddNewTeaVariety(backAddTeaMessageParam);
        return Result.success();
    }

    @PostMapping("/backUpdateTeaMessageById")
    @ApiOperation("后台更新茶种信息（主信息）")
    @CheckAuthorityStatus
    public Result backUpdateTeaMessageById(@RequestBody BackUpdateTeaMessageParam backUpdateTeaMessageParam){
        teaManagementService.backUpdateTeaMessageById(backUpdateTeaMessageParam);
        return Result.success();
    }

    @PostMapping("/backUpdateTeaRemarksMessageById")
    @ApiOperation("后台更新茶种信息（备注信息）")
    @CheckAuthorityStatus
    public Result backUpdateTeaRemarksMessageById(@RequestBody List<BackUpdateTeaRemarksMessageParam> backUpdateTeaRemarksMessageParams){
        teaManagementService.backUpdateTeaRemarksMessageById(backUpdateTeaRemarksMessageParams);
        return Result.success();
    }

    @DeleteMapping("/backDeleteTeaMessageById")
    @ApiOperation("后台根据id数组删除茶种信息")
    @CheckAuthorityStatus
    public Result backDeleteTeaMessageById(@RequestBody List<Long> ids){
        teaManagementService.backDeleteTeaMessageById(ids);
        return Result.success();
    }

    @DeleteMapping("/backDeleteTeaRemarkMessageById")
    @ApiOperation("后台根据id数组删除茶种附加信息")
    @CheckAuthorityStatus
    public Result backDeleteTeaRemarkMessageById(@RequestBody List<Long> ids){
        teaManagementService.backDeleteTeaRemarkMessageById(ids);
        return Result.success();
    }

    @GetMapping("/findAllVariety")
    @ApiOperation("查询所有茶种图片类别")
    public Result findAllVariety(){
        return Result.success(teaManagementService.findAllVariety());
    }
}
